package com.erp.system.service.impl;

import com.erp.framework.constant.ConfigConstants;
import com.erp.framework.util.DictUtils;
import com.erp.system.domain.Customer;
import com.erp.system.mapper.CustomerMapper;
import com.erp.system.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName: CustomerServiceImpl.java
 * 业务层接口实现类的详细说明
 *
 * @author 类创建者姓名
 * @version 1.00
 * @Date 创建日期
 */
@Service

public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;


    @Override
    public List<Customer> queryAll(Customer customer) {
        return customerMapper.queryAll(customer);
    }

    @Override
    public int insertCustomer(Customer material) {
        return customerMapper.insertCustomer(material);
    }

    @Override
    public Customer queryCode(String code) {
        Customer param = new Customer();
        param.setCode(code);
        return queryAll(param).stream().findFirst().orElse(param);
    }

    @Override
    public Customer queryById(String id) {
        Customer param = new Customer();
        param.setId(id);
        return queryAll(param).stream().findFirst().orElse(param);
    }

    @Override
    public int updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer);
    }

    @Override
    public int deleteCustomerByIds(String[] id) {
        return customerMapper.deleteCustomerByIds(id);
    }

    @Override
    public boolean checkCodeUnique(Customer customer) {
        Customer param = new Customer();
        param.setCode(customer.getCode());
        List<Customer> list = queryAll(param);
        return !list.isEmpty() && list.stream().noneMatch(c -> c.getId().equals(customer.getId()));
    }

}
